-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EFX environment and reverb effect. Closes #697. #702
base: main
Are you sure you want to change the base?
Conversation
It can be used like this:
Multiple Sound instances can be attached to one effect slot. Effect slot can be binded to one effect. |
Codecov Report
@@ Coverage Diff @@
## master #702 +/- ##
==========================================
+ Coverage 18.11% 18.22% +0.10%
==========================================
Files 247 253 +6
Lines 22633 22765 +132
Branches 5808 5824 +16
==========================================
+ Hits 4101 4149 +48
- Misses 17395 17478 +83
- Partials 1137 1138 +1
Continue to review full report at Codecov.
|
#include "SoundEffect.hpp" | ||
#include "OpenAlExtensions.hpp" | ||
|
||
EffectSlot::EffectSlot() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using an initialization list
rwengine/src/audio/EffectSlot.cpp
Outdated
} | ||
|
||
void EffectSlot::setGain(float gain) { | ||
alAuxiliaryEffectSlotf(slotId, AL_EFFECTSLOT_GAIN, this->gain = gain); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Split a variable assigning and a function invocation
*/ | ||
std::shared_ptr<SoundEffect> effect; | ||
|
||
ALuint slotId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or you can set members to defaults right here
rwengine/src/audio/SoundEffect.hpp
Outdated
* @param type OpenAl specific effect type. | ||
*/ | ||
SoundEffect(ALint type); | ||
~SoundEffect(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should make the destructor virtual:
https://stackoverflow.com/questions/461203/when-to-use-virtual-destructors
rwengine/src/audio/ReverbEffect.hpp
Outdated
public: | ||
ReverbEffect(); | ||
|
||
void setDensity ( float density = 1.0f ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove table-like formatting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there should be some comments describing parameters that functions are setting
rwengine/src/audio/ReverbEffect.cpp
Outdated
alEffectf(id, AL_REVERB_LATE_REVERB_GAIN, g); | ||
} | ||
|
||
void ReverbEffect :: setLateReverbDelay (float t) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something wrong with a formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed it
rwengine/src/audio/Sound.hpp
Outdated
@@ -42,6 +43,8 @@ struct Sound { | |||
|
|||
void setMaxDistance(float maxDist); | |||
|
|||
void attachToEffectSlot(const std::shared_ptr<EffectSlot> effectSlot); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should pass a shared_ptr by const reference or by value and use std::move
rwengine/src/audio/SoundBuffer.cpp
Outdated
@@ -83,3 +86,11 @@ void SoundBuffer::setGain(float gain) { | |||
void SoundBuffer::setMaxDistance(float maxDist) { | |||
alCheck(alSourcef(source, AL_MAX_DISTANCE, maxDist)); | |||
} | |||
|
|||
void SoundBuffer::attachToEffectSlot(const std::shared_ptr<EffectSlot> slot) { | |||
alCheck(alSource3i(source, AL_AUXILIARY_SEND_FILTER, slot->getSlotId(), slot->getSlotNumber(), AL_FILTER_NULL)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use const reference here
rwengine/src/audio/SoundBuffer.cpp
Outdated
} | ||
|
||
void SoundBuffer::detachFromEffectSlot(const std::shared_ptr<EffectSlot> slot) { | ||
alCheck(alSource3i (source, AL_AUXILIARY_SEND_FILTER, AL_EFFECTSLOT_NULL, slot->getSlotNumber(), AL_FILTER_NULL)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above
rwengine/src/audio/SoundManager.cpp
Outdated
|
||
initEfxFunctionPointers(); | ||
|
||
SoundEffect effect(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have no idea what zero mean... Maybe define some constants?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just a test code, deleted.
rwengine/src/audio/ReverbEffect.h
Outdated
@@ -0,0 +1,11 @@ | |||
#ifndef REVERBEFFECT_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this file is unneeded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleted.
rwengine/src/audio/EffectSlot.cpp
Outdated
EffectSlot::EffectSlot() { | ||
alGenAuxiliaryEffectSlots(1, &slotId); | ||
|
||
effect = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default member initializer
I've kept possibility to manually operate on basic blocks It (should) make usage of Sounds simpler and prevent code duplication. So I think So code would become something:
I look forward to your opinion about this idea. ;) |
Suggested improvements look good to me. |
SoundEffect and SoundSlot is merged SoundManager contains all pre-initialized effects
@@ -18,8 +21,10 @@ struct Sound { | |||
std::shared_ptr<SoundSource> source; | |||
std::unique_ptr<SoundBuffer> buffer; | |||
|
|||
std::shared_ptr<SoundEffect> effect; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raw ptr is enough
@@ -2,6 +2,13 @@ | |||
|
|||
#include "audio/SoundBuffer.hpp" | |||
|
|||
Sound::~Sound() | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting. Use clang-format with our config file.
@@ -46,6 +53,12 @@ void Sound::setMaxDistance(float maxDist) { | |||
buffer->setMaxDistance(maxDist); | |||
} | |||
|
|||
void Sound::enableEffect(std::shared_ptr<SoundEffect> effect) | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also
@@ -307,10 +307,11 @@ void ObjectRenderer::renderVehicle(VehicleObject* vehicle, | |||
|
|||
void ObjectRenderer::renderPickup(PickupObject* pickup, RenderList& outList) { | |||
if (!pickup->isEnabled()) return; | |||
|
|||
|
|||
static constexpr float kRotationSpeedCoeff = 3.0f; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imho it's better to avoid unnecessary code in this pull.
@@ -117,6 +123,9 @@ class SoundManager { | |||
|
|||
/// Multiplier for music and cutscenes audio | |||
float _musicVolume = 1.f; | |||
|
|||
/// Available sound effects for sfx | |||
std::vector<std::shared_ptr<SoundEffect>> soundEffects; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::vector<std::unique_ptr<SoundEffect>> soundEffects;
should be enough. (pass raw ptr to Sound
s)
playSfx(name, position, SoundEffect::Type::Reverb, looping, maxDist); | ||
} | ||
|
||
void SoundManager::playSfx(size_t name, const glm::vec3& position, SoundEffect::Type effectType, bool looping, int maxDist) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting
|
||
// first effect is placeholder | ||
// it allows index to be like in enum | ||
soundEffects.push_back(nullptr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's better to remove None
from enum and add bool
enabled. I think there are too many parameters for sfx to pass them around. Probably we should add some abstraction/wrapper later.
// first effect is placeholder | ||
// it allows index to be like in enum | ||
soundEffects.push_back(nullptr); | ||
soundEffects.push_back(std::make_shared<ReverbEffect>()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit(not need to do in this pull): lazy initialization / do when there's need
@@ -83,3 +85,11 @@ void SoundBuffer::setGain(float gain) { | |||
void SoundBuffer::setMaxDistance(float maxDist) { | |||
alCheck(alSourcef(source, AL_MAX_DISTANCE, maxDist)); | |||
} | |||
|
|||
void SoundBuffer::enableEffect(std::shared_ptr<SoundEffect> effect) { | |||
alCheck(alSource3i(source, AL_AUXILIARY_SEND_FILTER, (ALint) effect->getSlotId(), effect->getSlotNumber(), AL_FILTER_NULL)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting
} | ||
|
||
void SoundBuffer::disableEffect(std::shared_ptr<SoundEffect> effect) { | ||
alCheck(alSource3i (source, AL_AUXILIARY_SEND_FILTER, AL_EFFECTSLOT_NULL, effect->getSlotNumber(), AL_FILTER_NULL)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also
@@ -1,9 +1,12 @@ | |||
#ifndef _RWENGINE_SOUND_HPP_ | |||
#define _RWENGINE_SOUND_HPP_ | |||
|
|||
#include <audio/SoundEffect.hpp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forward declaration
* Many sound sources can be attached to one slot. | ||
* Different effects can be binded to this (e.g reverb, delay). | ||
*/ | ||
class EffectSlot { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have problems with understanding connection between this class and SoundEffect
. I mean where is EffectSlot
created, used, deleted. Because instances of EffectSlot
and SoundEffect
are in relation 1 to 1. I think solution when one of them contains/owns instances of second would be good enough.
Do you need some help with changes? You can catch me on IRC. ;) |
Do you plan to continue work on this pull? |
Bump? |
Some classes to support EFX and realisation of a reverb.
Closes #697